package com.hqyj.crmdemo.controller;

import com.hqyj.crmdemo.entity.Custmer;
import com.hqyj.crmdemo.entity.RestResult;
import com.hqyj.crmdemo.entity.SaleChance;
import com.hqyj.crmdemo.service.ICustmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 何万林
 * @since 2022-10-17
 */
@RestController
@RequestMapping("/custmer")
@CrossOrigin
public class CustmerController {

    @Autowired
    ICustmerService service;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public RestResult<Custmer> queryAll() {
        List<Custmer> custmers = service.queryAll();
        return RestResult.ok(custmers);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public RestResult<Custmer> add(Custmer custmer) {
        Boolean aBoolean = service.add(custmer);
        if (aBoolean) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public RestResult<Custmer> delete(Integer custmerId) {
        Boolean aBoolean = service.delete(custmerId);
        if (aBoolean) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public RestResult<Custmer> update(Custmer custmer) {
        Boolean aBoolean = service.update(custmer);
        if (aBoolean) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }

}
